package com.sdry.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.entity.Content;
import com.sdry.mapper.ContentMapper;
import com.sdry.service.ContentService;

@Service
public class ContentServiceImpl implements ContentService {

	@Resource
	private ContentMapper contentMapper;
	
	@Override
	public List<Content> listPageContent(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return contentMapper.listPageContent(map);
	}

	@Override
	public Integer insertContent(Content content) {
		// TODO Auto-generated method stub
		return contentMapper.insertContent(content);
	}

	@Override
	public Integer updateContent(Content content) {
		// TODO Auto-generated method stub
		return contentMapper.updateContent(content);
	}

	@Transactional(rollbackFor={Exception.class})
	@Override
	public Integer deleteContent(String[] contentIDs) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			for (int i = 0; i < contentIDs.length; i++) {
				isSuccess = contentMapper.deleteContent(Long.parseLong(contentIDs[i]));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

	@Override
	public Content findContentByID(Long contentID) {
		// TODO Auto-generated method stub
		return contentMapper.findContentByID(contentID);
	}

}
